#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/4/9 11:34
# @Author  : ldh

from basic.device.Android import Android
from airtest.core.api import *
from basic.utils.h5View import H5View


class oclifePage(Android):
    MenuBtm="com.cloudbae.lovenanning:id/menu_logo"
    GuideLogo="com.cloudbae.lovenanning:id/guide_logo" #使用引导蒙层
    MoreScene="com.cloudbae.lovenanning:id/oc_grid_txt" #更多场景
    MoreFunction="com.cloudbae.lovenanning:id/oc_topRightMenu" #更多功能
    refreshBtm="com.cloudbae.lovenanning:id/qrRefresh" #如刷码失败，请刷新二维码后重试
    chanellName="com.cloudbae.lovenanning:id/channel_name" #更多场景名称
    EmptyBill="com.cloudbae.lovenanning:id/emptyView_hint_txt" #账单记录为空
    BillTitle="com.cloudbae.lovenanning:id/txtTL" #账单名称



    #点击一码通城按钮
    @classmethod
    def clickOclife(self):
        self.poco(oclifePage.MenuBtm).click()


    #如有蒙层，则先关闭使用引导蒙层
    @classmethod
    def closeGuide(self):
        if self.poco(self.GuideLogo).exists():
            a=self.poco(self.GuideLogo)
            for i in range(0,len(a)):
                self.poco(self.GuideLogo).click()
        else:
            print("没有一码通城使用引导蒙层")


    @classmethod
    def ifOclife(self):
        refreshTest=self.poco(self.refreshBtm)
        if refreshTest.exists():
            print(refreshTest.get_text())
            return True
        else:
            return False


    #支付设置
    @classmethod
    def clickPayChannel(self):
        self.poco(self.MoreFunction).click()
        self.poco(text="支付设置").click()

    @classmethod
    def getPayChannel(self):
        text=H5View.views(".*?免密支付设置")
        chanellList=[]
        for i in range(0,len(text)):
            chanellList.append(text[i].get_text())
        print(chanellList)
        return chanellList


    #更多场景
    @classmethod
    #点击更多场景按钮
    def clickMoreScene(self):
        self.poco(self.MoreScene)[4].click()

    @classmethod
    def getChannelFunction(self):
        chanellName=self.poco(self.chanellName)
        list=[]
        for i in range(0,len(chanellName)):
            list.append(chanellName[i].get_text())
            swipe((500, 2000), (500, 800))
        print(list)
        return list


    @classmethod
    # 点击账单记录
    def clickBills(self):
        self.poco(self.MoreFunction).click()
        self.poco(text="账单记录").click()

    @classmethod
    #判断账单列表是否为空
    def ifEmpty(self):
        emptyBill=self.poco(self.EmptyBill)
        if emptyBill.exists():
            a=emptyBill.get_text()
            print(a)
            return True
        else:
            return False

    @classmethod
    def billList(self):
        billTitle=self.poco(self.BillTitle)
        lenTitle=len(billTitle)
        billList=[]
        for i in range(0,lenTitle):
            billList.append(billTitle[i].get_text())
        print(billList)
        return billList























